import set from '@dfeidao/atom-web/local/set';
import error from '@dfeidao/atom-web/msgbox/error';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import a001 from './a001';
export default async function a002(fd: IFeidaoAiBrowserComponent) {
	// 模糊查询
	const search_names = fd.data.node.querySelector<HTMLInputElement>('[id="search_name"]').value;
	const search_conts = fd.data.node.querySelector<HTMLSelectElement>('[id="search_cont"]').value;
	let search_name = {};
	let search_cont = {};
	if (search_names) {
		search_name = { $regex: '.*' + search_names + '.*', $options: 'i' };
		set(fd, 'search_name', search_name);

	} else {
		set(fd, 'search_name', null);

	}
	if (search_conts) {
		search_cont = { $regex: '.*' + search_conts + '.*', $options: 'i' };
		set(fd, 'search_cont', search_cont);

	} else {
		set(fd, 'search_cont', null);

	}
	const begin = fd.data.node.querySelector<HTMLInputElement>('[id="time_begin"]');
	const end = fd.data.node.querySelector<HTMLInputElement>('[id="time_end"]');
	const begin_time = new Date(new Date(begin.value).toLocaleDateString()).getTime();
	const end_time = new Date(new Date(new Date(end.value).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1).getTime();
	if (begin_time > end_time) { error('开始时间不得大于结束时间 ！'); } else {
		set(fd, 'begin_time', begin_time);
		set(fd, 'end_time', end_time);
		a001(fd);
	}
}
